package com.qf.osmcart.cart.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.common.core.common.R;
import com.qf.osmcart.cart.param.CartParam;
import com.qf.osmcart.cart.service.CartService;
import com.qf.osmcart.cart.vo.CartVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 天--道--酬--勤
 *
 * @author LiangGaoQiang
 * @ClassName CartController
 * @Date: 2025/6/11 19:05
 * @Description: 描述
 */
@RestController
@RequestMapping("/Cart")
public class CartController {

    @Resource
    private CartService cartService;

    /**
     * 获取购物车数量
     *
     * @return
     */
    @RequestMapping("/getCartLength")
    public R getCartLength() {
        Integer cartLength = cartService.getCartLength();
        return R.ok(cartLength);
    }


    /**
     * 获取购物车列表
     *
     * @return 购物车列表
     */
    @GetMapping("/getCart")
    public R getCart(CartParam cartParam) {
        Page<CartVO> cartList = cartService.getCart(cartParam);
        return R.ok(cartList);
    }


    /**
     * 购物车商品选中和取消选中
     *
     * @param cartParam 购物车参数
     * @return 成功或者失败
     */
    @GetMapping("/pathCartChecked")
    public R pathCartChecked(CartParam cartParam) {
        Boolean checked = cartService.pathCartChecked(cartParam);
        if (checked) {
            return R.ok();
        } else {
            return R.fail();
        }
    }

}
